package edu.pku.sei.transformation.editor.controller.commands.node;

import org.eclipse.gef.commands.Command;

import edu.pku.sei.modeler.model.core.MetaPackage;
import edu.pku.sei.transformation.editor.internal.TransformationEditorModelRoot;
import edu.pku.sei.transformation.editor.model.Transformation;

public class TransformationDeleteCommand extends Command {
	private Transformation transformation;
	private MetaPackage transPackage;
	public TransformationDeleteCommand(Transformation transformation) {
		this.transformation = transformation;
		this.transPackage = TransformationEditorModelRoot.getTransformationPackage(transformation.getModel());
	}
	
	@Override
	public boolean canExecute() {
		if (this.transformation == null || this.transPackage == null) {
			return false;
		}
		return super.canExecute();
	}
	
	@Override
	public void execute() {
		this.transPackage.getOtherElements().remove(transformation);
	}
	
	@Override
	public void undo() {
		this.transPackage.getOtherElements().add(transformation);
	}
}
